package com.crazy.appium.page;

import java.util.List;

import com.crazy.appium.driver.CrazyMobileDriver;
import com.crazy.appium.utils.GetLocatorUtils;

import io.appium.java_client.MobileElement;

/**
 * @author 沙陌 qq2879897713
 *
 */
public class BasePage {

	public CrazyMobileDriver driver;
	public GetLocatorUtils locator;
	public String platform;

	public BasePage(CrazyMobileDriver driver, String platform) {
		this.driver = driver;
		this.platform = platform;
		String configfile = "configs/" + this.getClass().getSimpleName().toLowerCase() + ".properties";
		System.out.println(configfile);
		this.locator = new GetLocatorUtils(configfile);
	}
	public MobileElement getElement(String locatorValue){
		if(platform.equalsIgnoreCase("android")){
			//driver.findElement(By.xpath("com.example.tiantang:id/iv_bookshelf_header"))
			return driver.findElement(locator.getByLocator(locatorValue));
		}else{
			return driver.findElement(locator.getByLocator("ios_"+locatorValue));
		}
	}
	
	public List<MobileElement> getElements(String locatorValue){
		if(platform.equalsIgnoreCase("android")){
			return driver.findElements(locator.getByLocator(locatorValue));
		}else{
			return driver.findElements(locator.getByLocator("ios_"+locatorValue));
		}
	}


	public static void main(String[] args) {

	}

}
